package com.byf.search.controller;

import com.byf.common.core.domain.Result;
import com.byf.search.service.ProductService;
import com.byf.search.vo.SearchParam;
import com.byf.search.vo.SearchResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;

@RestController
public class EsSearchController {
    @Autowired
    private ProductService productService;

    /**
     * 商品es搜索
     * @param searchParam
     * @return
     */
    @GetMapping
    public Result<SearchResult> searchProduct(SearchParam searchParam) {
        try {
            SearchResult result = productService.search(searchParam);
            return Result.success(result);
        } catch (IOException e) {
            return Result.error(e.getMessage());
        }
    }
}
